# CodeName:MainWindows(Thermistor Calculator)
# Authon:liutao
# E-Mail:wxyj3496@126.com
# Creat time:2020-10-01
# Last Modified by:liutao
# Last Modified Time:2021-11-01
# futction:热敏电阻和温度切换

import tkinter as tk
from tkinter import ttk
import generic_liutao as ltgen
from tkinter import messagebox as msg
import math
import pandas as pd
import pickle

class MainWindow():

	def __init__(self):
		self.win = tk.Tk()
		self.win.title('ThermCalc')
		self.win.resizable(False, False)
		self.create_widgets()

	def _quit(self):
		self.win.quit()
		self.win.destroy()
		exit()

###################################################################################
# 类内函数
# 菜单About的信息定义
###################################################################################
	def _about(self):
		win_about = tk.Toplevel()
		win_about.title('About ThermCalc')
		about_name = tk.Label(win_about, text='ThermCalc')
		about_name.config(font=('Arial', 30), foreground='red', width=12)
		about_name.config(pady=5)
		about_name.pack()

		tk.Label(win_about, text='Designed by LiuTao @2020', pady=3).pack()
		tk.Label(win_about, text='E-mail: wxyj3496@126.com', pady=3).pack()
		tk.Label(win_about, text='Telephone: 13356981975', pady=3).pack()
		tk.Label(win_about, text='Version: D1.11', pady=3).pack()


###################################################################################
# 类内函数
# 进行温度转换，根据选择的转换类型，更改单位算出温度
###################################################################################
	def temptransCall(self):
		textin = self.temp_enterVar.get()
		textre = self.temp_resultVar

		if textin == '':
			msg.showinfo('ThermCalc Info Box', '请输入温度！')
		# -----------change the unit of temp-----------------------------
		else:
			radSel = self.radVar.get()
			if radSel == 0:
				self.unit_entered.configure(text='℃')
				self.unit_result.configure(text='K')
				textre.set(str(round(float(textin) + 273.15, 3)))
				# print(ltgen.is_number('+32'))
			elif radSel == 1:
				self.unit_entered.configure(text='℃')
				self.unit_result.configure(text='F')
				textre.set(str(round(float(textin) / 1.8 + 32, 3)))
			elif radSel == 2:
				self.unit_entered.configure(text='K')
				self.unit_result.configure(text='℃')
				textre.set(str(round(float(textin) - 273.15, 3)))
			elif radSel == 3:
				self.unit_entered.configure(text='K')
				self.unit_result.configure(text='F')
				textre.set(str(round((float(textin) + 273.15) / 1.8 + 32, 3)))
			elif radSel == 4:
				self.unit_entered.configure(text='F')
				self.unit_result.configure(text='℃')
				textre.set(str(round((float(textin) - 32) * 1.8, 3)))
			elif radSel == 5:
				self.unit_entered.configure(text='F')
				self.unit_result.configure(text='K')
				textre.set(str(round((float(textin) - 32) * 1.8 + 273.15, 3)))
			else:
				msg.showinfo('ThermCalc Info Box',\
						'请选择一个转换！')

###################################################################################
# 类内函数
# 判断输入的是否是数字
###################################################################################
	def testfloat(self, name_entry):
		widget = self.win.nametowidget(name_entry)
		textin = widget.get()

		if ltgen.is_number(textin):
			# msg.showinfo('ThermCalc Info Box','Pleaes input float.')
			return True
		else:
			widget.delete(0, tk.END)
			# msg.showinfo('ThermCalc Info Box','Pleaes input float1.')
			return False

###################################################################################
# 类内函数
# 更改热敏电阻a,b,c系数
###################################################################################
	def changeabc_NTC(self, event):
		choise_res = self.thermreschoise.get()
		a = self.factora_NTC_enterVar
		b = self.factorb_NTC_enterVar
		c = self.factorc_NTC_enterVar
		if choise_res == 'MF501':
			a.set('-6.01188')
			b.set('4622.53337')
			c.set('-86421.72414')
			self.thermres_type = 'ntc'
			self.label_upvolt.configure(text='上拉电压')
			self.label_upunit.configure(text='V')
			self.upvolt_enterVar.set(5)
		elif choise_res == 'MF61/MF601':
			a.set('-4.36216')
			b.set('4081.70194')
			c.set('-94033.78039')
			self.thermres_type = 'ntc'
			self.label_upvolt.configure(text='上拉电压')
			self.label_upunit.configure(text='V')
			self.upvolt_enterVar.set(5)
		elif choise_res == 'MF51-3000-3.9k':
			a.set('-3.051648504')
			b.set('3776.200666')
			c.set('-119566.8764')
			self.thermres_type = 'ntc'
			self.label_upvolt.configure(text='上拉电压')
			self.label_upunit.configure(text='V')
			self.upvolt_enterVar.set(5)
		elif choise_res == 'MF51-3000-8.2k':
			a.set('-2.308490903')
			b.set('3776.200666')
			c.set('-119566.876')
			self.thermres_type = 'ntc'
			self.label_upvolt.configure(text='上拉电压')
			self.label_upunit.configure(text='V')
			self.upvolt_enterVar.set(5)
		elif choise_res == 'MF51-3000-18k':
			a.set('-1.5222533')
			b.set('3776.200666')
			c.set('-119566.876')
			self.thermres_type = 'ntc'
			self.label_upvolt.configure(text='上拉电压')
			self.label_upunit.configure(text='V')
			self.upvolt_enterVar.set(5)
		elif choise_res == 'MF51-3000-30k':
			a.set('-2.251789232')
			b.set('4271.182215')
			c.set('-148413.1934')
			self.thermres_type = 'ntc'
			self.label_upvolt.configure(text='上拉电压')
			self.label_upunit.configure(text='V')
			self.upvolt_enterVar.set(5)
		elif choise_res == 'OtherNTC':
			a.set('-2.251789232')
			b.set('4271.182215')
			c.set('-148413.1934')
			self.thermres_type = 'ntc'
			msg.showinfo('ThermCalc Info Box',\
					'请输入a,b,c系数！')
			self.label_upvolt.configure(text='上拉电压')
			self.label_upunit.configure(text='V')
			self.upvolt_enterVar.set(5)
		elif choise_res == 'PT100':
			self.thermres_type = 'pt100'
			self.label_upvolt.configure(text='恒流源电流')
			self.label_upunit.configure(text='mA')
			self.df_pt100 = pd.read_pickle('PT100(-200-800).pickle')
			self.upvolt_enterVar.set(1)

		elif choise_res == 'PT1000':
			self.thermres_type = 'pt1000'
			self.label_upvolt.configure(text='恒流源电流')
			self.label_upunit.configure(text='mA')
			self.df_pt1000_1 = pd.read_pickle('PT1000(-50-100).pickle')
			self.df_pt1000_2 = pd.read_pickle('PT1000(100-300).pickle')
			self.upvolt_enterVar.set(0.1)
###################################################################################
# 类内函数
# 铂电阻核算函数
###################################################################################
	def colcptres(self,df_pt,temp,d):
		df_temp = df_pt['℃']
		n = 0
		m = 0
		for t in df_temp:
			# 若求的温度与列表相同，则设m = 1 直接退出循环
			if t == temp:
				m = 1
				break
			elif t > temp:
				m = 0
				break
			n = n + 1
		if m == 1:
			tempcalc = df_pt['0'][n]
		else:
			k = 0
			if d == 1:
				title = [0,1,2,3,4,5,6,7,8,9]
			elif d == 2:
				title = [0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9]
			for i in range(10):
				j = df_pt['℃'][n-1] + title[i]
				l = df_pt['℃'][n-1] + title[9]
				if j == temp:
					k = 1
					break
				elif j > temp:
					k = 0
					break
				elif temp > l and temp < df_pt['℃'][n]:
					k = 2
					j = l
					break
			if k == 1:
				tempcalc = df_pt[str(title[i])][n-1]
			elif k == 0:
				if d == 1:
					x = title[i]-1
					y = title[i]
				elif d == 2:
					x = round(title[i] -0.1,1)
					y = round(title[i],1)
					if x == 0.0:
						x = 0
					if y == 0.0:
						y = 0

				tempcalc = df_pt[str(x)][n-1]+(df_pt[str(y)][n-1]\
					-df_pt[str(x)][n-1])*(1-(j-temp)/title[1])
			elif k == 2:
				tempcalc = df_pt[str(9)][n-1]+(df_pt[str(0)][n]\
					-df_pt[str(9)][n-1])*((temp-j)/title[1])
		return tempcalc


###################################################################################
# 类内函数
# 将温度变为热敏电阻
###################################################################################

	def temp2restransCall(self):
		temp = self.temp2res_enterVar.get()
		upvolt = self.upvolt_enterVar.get()
		result_volt = self.temp2volt_result
		if self.thermres_type == 'ntc':
			
			a = self.factora_NTC_enterVar.get()
			b = self.factorb_NTC_enterVar.get()
			c = self.factorc_NTC_enterVar.get()
			upres = self.upres_enterVar.get()
			
			if temp == '':
				msg.showinfo('ThermCalc Info Box','请输入温度！')
			else:
				if a == '' or b == '' or c == '':
					msg.showinfo('ThermCalc Info Box', \
						'请输入a,b,c系数！')
				else:
					result_res = self.temp2thermres_result
					temp = float(temp)
					a = float(a)
					b = float(b)
					c = float(c)
					T = temp + 273.15
					tempcalc = math.exp(a+b/T+c/(T**2))
					tempcalc = round(tempcalc, 3)
					result_res.set(tempcalc)
	
				# -----clac the voltage of thermres----
					if upvolt == '':
						msg.showinfo('ThermCalc Info Box','请输入上拉电压！')
					elif upres == '':
						msg.showinfo('ThermCalc Info Box','请输入上拉电阻！')
					else:
						upvolt = float(upvolt)
						upres = float(upres)*1000
						devvoltcalc = upvolt * tempcalc/(tempcalc+upres)
						devvoltcalc = round(devvoltcalc, 3)
						result_volt.set(devvoltcalc)
		elif self.thermres_type == 'pt100':
			#upvolt = self.upvolt_enterVar.get()
			#temp = self.temp2res_enterVar.get()
			#result_volt = self.temp2volt_result
			if temp == '':
				msg.showinfo('ThermCalc Info Box','请输入温度！')
			else:
				result_res = self.temp2thermres_result
				temp = float(temp)
				if temp > 809 or temp < -200:
					msg.showinfo('ThermCalc Info Box','温度超范围，请重新输入！\n有效范围为-200℃～809℃!')
				else:
					tempcalc = self.colcptres(self.df_pt100,temp,1)
					tempcalc = round(tempcalc, 3)
					result_res.set(tempcalc)

					if upvolt == '':
						msg.showinfo('ThermCalc Info Box','请输入恒流源电流！')
					else:
						upvolt = float(upvolt)
						devvoltcalc = upvolt * tempcalc /1000
						devvoltcalc = round(devvoltcalc, 6)
						result_volt.set(devvoltcalc)

		elif self.thermres_type == 'pt1000':
			#upvolt = self.upvolt_enterVar.get()
			#temp = self.temp2res_enterVar.get()
			#result_volt = self.temp2volt_result

			if temp == '':
				msg.showinfo('ThermCalc Info Box','请输入温度！')
			else:
				result_res = self.temp2thermres_result
				temp = float(temp)
				if temp > 300 or temp < -50:
					msg.showinfo('ThermCalc Info Box','温度超范围，请重新输入！\n有效范围为-50℃～300℃!')
				else:
					if temp == 300:
						tempcalc = 2120.515
					elif temp > 299 and temp < 300:
						tempcalc = 2116.953 + (2120.515 - 2116.953) * (temp - 299)
					elif temp > 99.9 and temp < 100:
						tempcalc = 1384.676 + (1385.055 - 1384.676) * (temp - 99.9) * 10
					elif temp >= -50 and temp <= 99.9:
						tempcalc = self.colcptres(self.df_pt1000_1,temp,2)
					elif temp >= 100 and temp <= 299:
						tempcalc = self.colcptres(self.df_pt1000_2,temp,1)
						
					tempcalc = round(tempcalc, 3)
					result_res.set(tempcalc)

					if upvolt == '':
						msg.showinfo('ThermCalc Info Box','请输入恒流源电流！')
					else:
						upvolt = float(upvolt)
						devvoltcalc = upvolt * tempcalc /1000
						devvoltcalc = round(devvoltcalc, 6)
						result_volt.set(devvoltcalc)


###################################################################################
# 类内函数
# 铂电阻温度计算
###################################################################################
	def calcpttep(self,df_pt,res,d):
		df_res = df_pt['0']
		n = 0
		m = 0
		for r in df_res:
			# 若求的电阻与列表相同，则设m = 1 直接退出循环
			if r == res:
				m = 1
				break
			elif r > res:
				m = 0
				break
			n = n + 1
		if m == 1:
			rescalc = df_pt['℃'][n]
		else:
			k = 0
			if d == 1:
				title = [0,1,2,3,4,5,6,7,8,9]
			elif d == 2:
				title = [0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9]
			for i in range(10):
				j = df_pt[str(title[i])][n-1]
				l = df_pt[str(title[9])][n-1]
				if j == res:
					k = 1
					break
				elif j > res:
					k = 0
					break
				elif res > l and res < df_pt['0'][n]:
					k = 2
					j = l
					break
			if k == 1:
				rescalc = df_pt['℃'][n-1] + title[i]
			elif k == 0:
				x = title[i-1]
				y = title[i]

				rescalc = (res-df_pt[str(x)][n-1])/(j-df_pt[str(x)][n-1])*title[1]\
					+(df_pt['℃'][n-1] + title[i-1])
			elif k == 2:
				rescalc = (res-j)/(df_pt[str(title[0])][n]-j)*title[1]+(df_pt['℃'][n-1] + title[9])
		return rescalc


###################################################################################
# 类内函数
# 将温度变为热敏电阻
###################################################################################


	def res2temptransCall(self):
		res = self.res2temp_enterVar.get()
		upvolt = self.upvolt_enterVar.get()
		result_volt = self.thermres2volt_result
		#计算ntc电阻
		if self.thermres_type == 'ntc':
			a = self.factora_NTC_enterVar.get()
			b = self.factorb_NTC_enterVar.get()
			c = self.factorc_NTC_enterVar.get()
			upres = self.upres_enterVar.get()
			
			if res == '':
				msg.showinfo('ThermCalc Info Box', '请输入电阻.')
			elif float(res) <= 0.0:
				msg.showinfo('ThermCalc Info Box', '电阻不能为0或负值.')
			else:
				if a == '' or b == '' or c == '':
					msg.showinfo('ThermCalc Info Box', \
						'请输入a,b,c系数！')
				else:
					result_temp = self.thermres2temp_result
					res = float(res)
					a = float(a)
					b = float(b)
					c = float(c)
					rescalc = 2*c / (-b+math.sqrt(b*b-4*c*(a-math.log(res, math.e))))-273.15
					rescalc = round(rescalc, 3)
					result_temp.set(rescalc)
					if upvolt == '' or upres == '':
						msg.showinfo('ThermCalc Info Box','请输入上拉电压或上拉电阻！')
					else:
						upvolt = float(upvolt)
						upres = float(upres) * 1000
						devvoltcalc = upvolt * res / (res + upres)
						devvoltcalc = round(devvoltcalc, 3)
						result_volt.set(devvoltcalc)
		#计算铂电阻pt100
		elif self.thermres_type == 'pt100':
			if res == '':
				msg.showinfo('ThermCalc Info Box', '请输入电阻.')
			elif float(res) <= 0.0:
				msg.showinfo('ThermCalc Info Box', '电阻不能为0或负值.')
			else:
				result_temp = self.thermres2temp_result
				res = float(res)
				if res > 378.19 or res < 18.52:
					msg.showinfo('ThermCalc Info Box','电阻超范围，请重新输入！\n有效范围为18.52Ω～378.19Ω!')
				else:
					rescalc = self.calcpttep(self.df_pt100,res,1)
					rescalc = round(rescalc, 3)
					result_temp.set(rescalc)
					if upvolt == '':
						msg.showinfo('ThermCalc Info Box','请输入恒流源电流！')
					else:
						upvolt = float(upvolt)
						devvoltcalc =upvolt * res/ 1000
						devvoltcalc = round(devvoltcalc, 6)
						result_volt.set(devvoltcalc)
		# 计算铂电阻pt1000
		elif self.thermres_type == 'pt1000':
			if res == '':
				msg.showinfo('ThermCalc Info Box', '请输入电阻.')
			elif float(res) <= 0.0:
				msg.showinfo('ThermCalc Info Box', '电阻不能为0或负值.')
			else:
				result_temp = self.thermres2temp_result
				res = float(res)
				if res > 2120.515 or res < 803.063:
					msg.showinfo('ThermCalc Info Box','电阻超范围，请重新输入！\n有效范围为803.063Ω～2120.515Ω!')
				else:
					if res == 2120.515:
						rescalc = 300
					elif res > 2116.953 and res < 2120.515:
						rescalc = (res-2116.953)/(2120.515-2116.953)*0.1+299
					elif res > 1384.676 and res < 1385.055:
						rescalc = (res-1384.676)/(1385.055-1384.676)*0.1+99.9
					elif res >= 803.063 and res <= 1384.676:
						rescalc = self.calcpttep(self.df_pt1000_1,res,2)
					elif res >= 1385.055 and res <= 2116.953:
						rescalc = self.calcpttep(self.df_pt1000_2,res,1)
				
					rescalc = float(rescalc)
					rescalc = round(rescalc, 3)
					result_temp.set(rescalc)
					if upvolt == '':
						msg.showinfo('ThermCalc Info Box','请输入恒流源电流！')
					else:
						upvolt = float(upvolt)
						res = float(res)
						devvoltcalc =upvolt * res/ 1000
						devvoltcalc = round(devvoltcalc, 6)
						result_volt.set(devvoltcalc)

###################################################################################
# 类内函数
# 布置窗口
###################################################################################
	def create_widgets(self):
		# ==============================菜单栏================================
		menu_bar = tk.Menu(self.win)
		self.win.config(menu=menu_bar)

		file_menu = tk.Menu(menu_bar, tearoff=0)
		menu_bar.add_cascade(label='File', menu=file_menu)
		file_menu.add_command(label='Exit', command=self._quit)

		help_menu = tk.Menu(menu_bar, tearoff=0)
		menu_bar.add_cascade(label='Help', menu=help_menu)
		help_menu.add_command(label='About ThermCalc', command=self._about)

	# ===================================选项卡===============================
		tabControl = ttk.Notebook(self.win)
		tab_Transform = ttk.Frame(tabControl)
		tabControl.add(tab_Transform, text='装换')
		tab_Accuracy = ttk.Frame(tabControl)
		tabControl.add(tab_Accuracy, text='精度')

		tabControl.pack(expand=1, fill='both')

		# ===================温度转换 LabFrame==========================

		frame_temptran = ttk.LabelFrame(tab_Transform, text='温度转换',\
			height=2000, width=50)
		frame_temptran.grid(row=0, column=0, padx=3, pady=4)

		frame_thermrestran = ttk.LabelFrame(tab_Transform, text='温度与热敏电阻转换')
		frame_thermrestran.grid(row=1, column=0, padx=3, pady=4, columnspan=2)

		# ===================温度转换的Widget===================

		# -------------------转换方式的radio --------------------------
		choise_trans = ['摄氏度转开尔文', '摄氏度转华氏度',\
					'开尔文转摄氏度', '开尔文转华氏度',\
					'华氏度转摄氏度', '华氏度转开尔文']

		self.radVar = tk.IntVar()
		self.radVar.set(0)
		for cho in range(6):
			radTran = tk.Radiobutton(frame_temptran, text=choise_trans[cho],\
				variable=self.radVar, value=cho, command=self.temptransCall)
			radTran.grid(row=cho//3, column=cho % 3*2, sticky='W',columnspan=2,padx=5)

		# -------------------转换结果----------------------------
		self.temp_enterVar = tk.StringVar()  # define the variable of enter
		self.temp_resultVar = tk.StringVar()  # define the variable of result
		ttk.Label(frame_temptran, text='输入').grid(row=2,\
			column=0, padx=5, columnspan=2, sticky='WN',pady=5)
		ttk.Label(frame_temptran, text='结果').grid(row=2,\
			column=2, padx=5, columnspan=2, sticky='WN',pady=5)

		self.testtemp = self.win.register(self.testfloat) #注册函数
		self.temp_entered = ttk.Entry(frame_temptran, width=12,\
			textvariable=self.temp_enterVar, validate='focusout',\
			validatecommand=(self.testtemp, '%W'))
		self.temp_entered.grid(row=3, column=0, padx=5, sticky='W')
		temp_transresult = ttk.Entry(frame_temptran, width=12,\
			textvariable=self.temp_resultVar, state='readonly')
		temp_transresult.grid(row=3, column=2, padx=5, sticky='W')

		self.unit_entered = ttk.Label(frame_temptran, text='')
		self.unit_entered.grid(row=3, column=1, sticky='W')
		self.unit_result = ttk.Label(frame_temptran, text='')
		self.unit_result.grid(row=3, column=3, sticky='W')

		self.temp_enterVar.set('')
		self.temp_resultVar.set('')
		ttk.Button(frame_temptran, text='确定',\
			command=self.temptransCall).grid(row=3, column=4,\
			sticky='W', padx=5)

		# =================热敏电阻转换的widgets=================
		self.temp2res_enterVar = tk.StringVar()  # define variable of temp2res
		self.thermreschoise = tk.StringVar()  # define the choise of thermres
		self.temp2thermres_result = tk.StringVar()  # define the result of thermres

		ttk.Label(frame_thermrestran, text='选择热敏电阻类型'\
			).grid(row=0, column=0, padx=5, sticky='W', columnspan=3, pady=5)

		# --------热敏电阻下拉菜单----------------------
		thermres_chosen = ttk.Combobox(frame_thermrestran, width=15,\
			textvariable=self.thermreschoise, state='readonly')
		thermres_chosen['value'] = ('MF501', 'MF61/MF601', 'MF51-3000-3.9k',\
			'MF51-3000-8.2k', 'MF51-3000-18k', 'MF51-3000-30k', 'OtherNTC','PT100','PT1000')
		thermres_chosen.current(0)
		thermres_chosen.bind('<<ComboboxSelected>>', self.changeabc_NTC)
		thermres_chosen.grid(row=1, column=0, padx=5, sticky='W',\
			columnspan=2)
		# 赋热敏电阻类型初值
		self.thermres_type = 'ntc'

		# ----输入温度计算电阻-----------------
		ttk.Label(frame_thermrestran, text='温度转电阻'\
			).grid(row=4, column=0, padx=5, sticky='W', columnspan=3, pady=5)

		self.temp2res_entered = ttk.Entry(frame_thermrestran, width=12,\
			textvariable=self.temp2res_enterVar, validate='focusout',\
			validatecommand=(self.testtemp, '%W'))
		self.temp2res_entered.grid(row=5, column=0, padx=5, sticky='W')

		ttk.Label(frame_thermrestran, text='℃').grid(row=5,\
			column=1, sticky='W')

		temp2res_transresult = ttk.Entry(frame_thermrestran, width=12,\
			textvariable=self.temp2thermres_result, state='readonly')
		temp2res_transresult.grid(row=5, column=2, padx=5, sticky='W')

		ttk.Label(frame_thermrestran, text='Ω').grid(row=5,\
			column=3, sticky='W')

		ttk.Button(frame_thermrestran, text='确认',\
			command=self.temp2restransCall).grid(row=6, column=4,\
			sticky='W', padx=5, pady=10)

		# ----输入电阻计算温度-----------------
		self.res2temp_enterVar = tk.StringVar()  # define the enter of thermres
		self.thermres2temp_result = tk.StringVar()  # define the result of temp
		ttk.Label(frame_thermrestran, text='电阻转温度'\
			).grid(row=7, column=0, padx=5, sticky='W', columnspan=3)

		res2temp_entered = ttk.Entry(frame_thermrestran, width=12,\
			textvariable=self.res2temp_enterVar, validate='focusout',\
			validatecommand=(self.testtemp, '%W'))
		res2temp_entered.grid(row=8, column=0, padx=5, sticky='W')
		ttk.Label(frame_thermrestran, text='Ω').grid(row=8,\
			column=1, sticky='W')

		res2temp_transresult = ttk.Entry(frame_thermrestran, width=12,\
			textvariable=self.thermres2temp_result, state='readonly')
		res2temp_transresult.grid(row=8, column=2, padx=5, sticky='W')

		ttk.Label(frame_thermrestran, text='℃').grid(row=8,\
			column=3, sticky='W')
		ttk.Button(frame_thermrestran, text='确认',\
			command=self.res2temptransCall).grid(row=9, column=4,\
			sticky='W', padx=5, pady=10)

		# ------------输入电压和上拉电阻-------------------
		self.upvolt_enterVar = tk.StringVar()
		self.upres_enterVar = tk.StringVar()
		self.temp2volt_result = tk.StringVar()
		self.thermres2volt_result = tk.StringVar()

		self.label_upvolt = ttk.Label(frame_thermrestran, text='上拉电压')
		self.label_upvolt.grid(row=0,column=2, padx=5, sticky='W', columnspan=2)
		self.upvoltage_entered = ttk.Entry(frame_thermrestran, width=12,\
			textvariable=self.upvolt_enterVar, validate='focusout',\
			validatecommand=(self.testtemp, '%W'))
		self.upvolt_enterVar.set(5)
		self.upvoltage_entered.grid(row=1, column=2, padx=5, sticky='W')
		self.label_upunit = ttk.Label(frame_thermrestran, text='V')
		self.label_upunit.grid(row=1,column=3, padx=5, sticky='W')

		ttk.Label(frame_thermrestran, text='上拉电阻').grid(row=0,\
			column=4, padx=5, sticky='W', columnspan=2)
		self.upresistor_entered = ttk.Entry(frame_thermrestran, width=12,\
			textvariable=self.upres_enterVar, validate='focusout',\
			validatecommand=(self.testtemp, '%W'))
		self.upres_enterVar.set(10)
		self.upresistor_entered.grid(row=1, column=4, padx=5, sticky='W')
		ttk.Label(frame_thermrestran, text='kΩ').grid(row=1,\
			column=5, padx=5, sticky='W')

		temp2volt_transresult = ttk.Entry(frame_thermrestran, width=12,\
			textvariable=self.temp2volt_result, state='readonly')
		temp2volt_transresult.grid(row=5, column=4, padx=5, sticky='W')
		ttk.Label(frame_thermrestran, text='V').grid(row=5,\
			column=5, sticky='W')

		thermres2volt_transresult = ttk.Entry(frame_thermrestran, width=12,\
			textvariable=self.thermres2volt_result, state='readonly')
		thermres2volt_transresult.grid(row=8, column=4, padx=5, sticky='W')
		ttk.Label(frame_thermrestran, text='V').grid(row=8,\
			column=5, sticky='W')
		# ---------------热敏电阻系数------------------------
		self.factora_NTC_enterVar = tk.StringVar()
		self.factorb_NTC_enterVar = tk.StringVar()
		self.factorc_NTC_enterVar = tk.StringVar()

		ttk.Label(frame_thermrestran, text='a').grid(row=2,\
			column=0, padx=5, sticky='W', columnspan=3, pady=5)
		ttk.Label(frame_thermrestran, text='b').grid(row=2,\
			column=2, padx=5, sticky='W', columnspan=3, pady=5)
		ttk.Label(frame_thermrestran, text='c').grid(row=2,\
			column=4, padx=5, sticky='W', columnspan=3, pady=5)

		self.factora_NTC_entered = ttk.Entry(frame_thermrestran, width=12,\
			textvariable=self.factora_NTC_enterVar, validate='focusout',\
			validatecommand=(self.testtemp, '%W'))
		self.factora_NTC_entered.grid(row=3, column=0, padx=5, sticky='W')
		self.factorb_NTC_entered = ttk.Entry(frame_thermrestran, width=12,\
			textvariable=self.factorb_NTC_enterVar, validate='focusout',\
			validatecommand=(self.testtemp, '%W'))
		self.factorb_NTC_entered.grid(row=3, column=2, padx=5, sticky='W')
		self.factorc_NTC_entered = ttk.Entry(frame_thermrestran, width=12,\
			textvariable=self.factorc_NTC_enterVar, validate='focusout',\
			validatecommand=(self.testtemp, '%W'))
		self.factorc_NTC_entered.grid(row=3, column=4, padx=5, sticky='W')

		self.factora_NTC_enterVar.set('-6.01188')
		self.factorb_NTC_enterVar.set('4622.53337')
		self.factorc_NTC_enterVar.set('-86421.72414')


# =====================================================================
win_main = MainWindow()
win_main.win.mainloop()
